using System;
using UnityEngine;

public class LeaderboardsInfoButton : MonoBehaviour
{
	public UILabel nameLabel;

	public UILabel abilityLabel;

	public UISprite flagSprite;

	public UILabel tokensCollectedLabel;

	public UILabel leaderboardButtonLabel;

	private bool prevIsActive;

	public void Init()
	{
		UITools.ChangeText(nameLabel, GGPlayerSettings.instance.GetName());
	}

	public void OnEnable()
	{
		UpdateView();
		UITools.ChangeText(abilityLabel, "Ability: " + GGPlayerSettings.instance.GetDisplayEloRating().ToString());
		UITools.ChangeText(nameLabel, BehaviourSingletonInit<FriendProfilesManager>.instance.PlayerName);
		GameConstants.SetFlag(flagSprite, GGPlayerSettings.instance.Model.flag);
		BehaviourSingletonInit<GGPrizesBackend>.instance.onRefreshed -= OnRefreshed;
		BehaviourSingletonInit<GGPrizesBackend>.instance.onRefreshed += OnRefreshed;
	}

	private void OnRefreshed()
	{
		UpdateView();
	}

	public void OnDisable()
	{
		BehaviourSingletonInit<GGPrizesBackend>.instance.onRefreshed -= OnRefreshed;
	}

	public void UpdateView()
	{
		GGPrizesBackend instance = BehaviourSingletonInit<GGPrizesBackend>.instance;
		bool flag = instance.HasActiveCompTimestamp();
		if (flag)
		{
			TimeSpan span = BehaviourSingletonInit<GGPrizesBackend>.instance.TimeToCompEnd();
			UITools.ChangeText(leaderboardButtonLabel, "League: " + GGFormat.FormatTimeSpan(span));
		}
		else
		{
			UITools.ChangeText(leaderboardButtonLabel, "Leaderboards");
		}
		prevIsActive = flag;
	}

	private void Update()
	{
		GGPrizesBackend instance = BehaviourSingletonInit<GGPrizesBackend>.instance;
		bool flag = instance.HasActiveCompTimestamp();
		if (flag || prevIsActive != flag)
		{
			UpdateView();
		}
	}
}
